﻿using LY.Entity.PageSearch;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LY.Entity;
using LY.Entity.SearchEntity;
namespace LY.DataAccess.Repository
{
  public  class LinksRepository : BaseRepository
    {
        /// <summary>
        /// 根据主键ID检索链接信息,返回单个实体对象
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public C_Links GetLinks(int? id)
        {
            string sql = @" SELECT [Id]
                          ,[LinkType]
                          ,[LinkName]
                          ,[LinkImg]
                          ,[LinkUrl]
                          ,[AddTime]
                          ,[IsDisplay]
                          ,[Sequence]
                           FROM [C_Links] WHERE Id=@ID";
            return base.Get<C_Links>(sql, new { ID = id });
        }

      //查询出所有的友情链接
      public PagedList<C_Links> LinksList(LinksSearch search, PageView view)
      {
          string cols = @"[Id]
                          ,[LinkType]
                          ,[LinkName]
                          ,[LinkImg]
                          ,[LinkUrl]
                          ,[AddTime]
                          ,[IsDisplay]
                          ,[Sequence] ";
          string sqlWhere = "";
          if (!string.IsNullOrEmpty(search.LinkUrl))
          {
              sqlWhere += " AND [LinkName] LIKE '%" + search.LinkUrl + "%' or LinkUrl like '%" + search.LinkUrl + "%'";
          }
          return base.PageGet<C_Links>(view, cols, @" [C_Links] ", sqlWhere, "[Id] ASC", "");
      }
      //删除一条友情链接
      public int DeleteLinks(int id) {
          string sql = "delete from C_Links where Id=@ID";
          return base.Excute(sql, new {ID=id });
      }
    }
}
